
const app = getApp()
Page({
  data: {

  },
  onLoad: function (options) {

  },
  getUserInfo(e) {
    let that = this;
    // 获取用户信息
    app.WxService.login().then(data => {
      let code = data.code
      app.WxService.getSetting().then(res => {
        if (res.authSetting['scope.userInfo']) { // // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          app.globalData.Permission = true
          app.WxService.getUserInfo().then(data => {
            app.globalData.userInfo = data.userInfo
            let obj = {}
            obj.userInfo = {}
            obj.code = code
            obj.userInfo.userInfo = data.userInfo
            obj.userInfo.errMsg = data.errMsg
            obj.userInfo.rawData = data.rawData
            obj.userInfo.encryptedData = data.encryptedData
            obj.userInfo.iv = data.iv
            obj.userInfo.signature = data.signature

            app.Http.http({
              url: app.Api.Login,
              method: 'POST',
              params: obj
            }).then(data => {
              app.globalData.token = data.token
              app.globalData.userRole = data.userRole
              app.globalData.userId = data.userId
              let userObj = Object.assign({
                userRole: data.userRole,
                userId: data.userId
              }, data.userInfo)

              app.Store.set("token", data.token)
              app.Store.set("user", userObj)

              app.goBack({}, 2, 1)
            }).catch(err => {
              console.log(err)
            })


          })

        } else {
          app.globalData.Permission = false
          app.globalData.userInfo = null
        }
      })
    })

  },
  changeData(data) {
    
  }
})